import VueRouter from 'vue-router'
import About from '../pages/About'
import Home from '../pages/Home'
import News from '../pages/News'
import Message from '../pages/Message'
import Detail from '../pages/Detail'

const router= new VueRouter({
    mode:'history',
    routes:[
        {
            path:"/about",
            name:"guanyu",
            component:About,
            redirect:'/home',
            meta:{isAuth:false,title:"关于"}
        },
        {
            path:"/home",
            name:"zhuye",
            component:Home,
            meta:{isAuth:false,title:"主页"},
            children:[
                {
                    path:"news",
                    name:"xinwen",
                    component:News,
                    meta:{isAuth:false,title:"新闻"},
                    beforeEnter(to,from,next){
                        next();
                        console.log("路由守卫")
                    }
                },
                {

                    path:"message",
                    name:"xiaoxi",
                    component:Message,
                    meta:{isAuth:false,title:"消息"},
                    children:[
                        {
                            name:"xiangqing",
                            //path:"detail/:id/:title",
                            path:"detail",
                            component:Detail,
                            meta:{isAuth:false,title:"详情"},
                            //将props里的数据当作Detail组件的props属性
                            // props:{
                            //     a:1,
                            //     b:22
                            // }
                           // props:true,//将params参数当作Detail组件的props属性

                            // props($route){
                            //     console.log("props:",$route)
                            //     return {id:$route.query.id,title:$route.query.title}
                            // }
                        }
                    ]
                }
            ]
        }
    ]
})

// router.beforeEach((to,from,next)=>{
//     console.log(to,from)
//
//     const actions = ["zhuye","xinwen","guanyu"];
//     if(actions.includes(to.name)){
//         next()
//     }else{
//         alert("进不了")
//     }
// })
//后置全局路由守卫  切换路由时调用
router.afterEach((to,from)=>{

    document.title=to.meta.title
})
export default router